<!DOCTYPE html>
<html lang="en">
    <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Vue Template</title>
</head>
<body>
    <div id="app">
        <h1>{{counter}}</h1>
        <button v-on:click="add">+</button>
        <button @click="sub">-</button>
        <div @click="divClick">
            <!-- @click.stop阻止事件冒泡 -->
            <button @click.stop="btnClick">按钮</button>
        </div>
        <form action="baidu">
            <!-- @click.prevent阻止默认事件 -->
            <input type="submit" value="提交" @click.prevent="submit">
        </form>

        <!-- @keyup.enter监听enter键up事件 -->
        <input type="text" @keyup.enter="keyup">
    </div>
<script src="../js/vue.js"></script>
<script>
    const app = new Vue({
        el: '#app',
        data: {
            counter:0
        },
        methods: {
            add() {
                console.log();
                this.counter++
            },
            sub() {
                this.counter--
            },
            divClick(){
                console.log("divClick");
            },
            btnClick(){
                console.log("btnClick");
            },
            submit(){
                console.log("submit");
            },
            keyup(e){
                console.log(e.key);
            }
        },
    })
</script>
</body>
</html>